package jdk8_collection;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @author 07509-Chang Shengwei
 * @version Id: IteratorTest.java, v 0.1 2021/6/8 11:30 Chang Shengwei Exp $
 * @description 测试Iterator接口的forEachRemaining(Consumer < ? super E > action)
 */
public class IteratorTest {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("a", "b", "c", "d", "e");

        Iterator<String> iterator = list.iterator();

        iterator.forEachRemaining(System.out::println);
        // 但是action不能对集合进行修改
        iterator.forEachRemaining(x -> x = "yes?");
        System.out.println(list);
    }


}
